package com.servlet.yanglaoyuan.service.impl;

import com.servlet.yanglaoyuan.mapper.Medication_RecordMapper;
import com.servlet.yanglaoyuan.pojo.Medication_Record;
import com.servlet.yanglaoyuan.pojo.dataFilter;
import com.servlet.yanglaoyuan.service.Medication_RecordService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class Medication_RecordServiceImpl implements Medication_RecordService {
    @Autowired
    private Medication_RecordMapper medication_RecordMapper;
    @Results({
            @Result(property = "date", column = "date", javaType = LocalDateTime.class)
    })
    //添加一条用药记录
    @Override
    public void add(Medication_Record medication_record){
        medication_RecordMapper.add(medication_record);
    }

    //修改一条用药记录
    @Override
    public void updateRecord(Medication_Record medication_record){
        medication_RecordMapper.updateRecord(medication_record);
    }

    //根据名称查询一条用药记录
    @Override
    public List<Medication_Record> getByName(String medicationName){
        return medication_RecordMapper.getByName(medicationName);
    }

    //根据状态查询一条用药记录
    @Override
    public List<Medication_Record> getByStatus(String status){
        return medication_RecordMapper.getByStatus(status);
    }

    //根据时间查询一条用药记录
    @Override
    public List<Medication_Record> getByDate(LocalDateTime startDate, LocalDateTime endDate){
        return medication_RecordMapper.getByDate(startDate,endDate);
    }

    //删除一条用药记录
    @Override
    public void deleteRecord(Integer id){
        medication_RecordMapper.deleteRecord(id);
    }

    //查询所有用药记录
    @Override
    public List<Medication_Record> getAll(){
        return medication_RecordMapper.getAll();
    }

    @Override
    public List<Medication_Record> getByElderlyId(Integer elderlyId){
        return medication_RecordMapper.getByElderlyId(elderlyId);
    }

    //筛选用药记录
    @Override
    public List<Medication_Record> getRecord(dataFilter record){
        return medication_RecordMapper.getRecord(record);
    }
}
